package org.example.aop.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.example.aop.dto.request.UserRequest;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Description:
 */
@Aspect
@Component
@Order(1)
public class PermissionFirstAdvice {
    // 定义一个切面，拦截所有注解了@PermissionAnnotation的方法
    @Pointcut("@annotation(org.example.aop.annotation.PermissionAnnotation)")
    private void permissionCheck() {
    }

    @Around("permissionCheck()")
    public Object permissionCheckFirst(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("===================第一个切面===================：" + System.currentTimeMillis());

        //获取请求参数，详见接口类
        Object[] objects = joinPoint.getArgs();
        // 这样会导致这个切面无法公共使用
        UserRequest userRequest = (UserRequest) objects[0];
        System.out.println(userRequest);

        // 执行下一个逻辑
        return joinPoint.proceed();
    }
}
